const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/playground",{useUnifiedTopology: true,useNewUrlParser: true})
  .then(()=>{console.log('数据库连接成功')})
  .catch(err=>{console.log('数据库连接失败')})

//创建集合规则
let courseSchema = new mongoose.Schema({
  name:String,
  author:String,
  isPublished:Boolean
})

//使用规则创建集合
const Course = mongoose.model('Course',courseSchema)  //courses
const course = new Course({
  name:'nodejs基础',
  author:"xdj",
  isPublished:true
})
course.save();